package repository;

import java.util.List;

import prefix.util.JPAUtil;
import prefix.util.jpaQueryfier.JpaQueryfier;

import models.Transaction;
import models.Transaction.Type;

public class TransactionRepository extends AbstractRepository {

    private static String getLoanIssueTransactionsSQL = null;

    public static List<Transaction> getLoanIssueTransactions(Integer LoanId) {
        if (getLoanIssueTransactionsSQL == null) {
            String inType = buildInList(Type.T2_LENDER_ISSUE_FUNDS_TO_BORROWER, Type.T4_BORROWER_PAY_ORIG_FEE);
            StringBuilder builder = new StringBuilder();
            builder.append(" select * from transaction ");
            builder.append(" where type in ").append(inType);
            builder.append(" and status = 0 ");
            builder.append(" and loan_id = :loan_id ORDER BY ID ASC ");
            getLoanIssueTransactionsSQL = builder.toString();
        }

        return new JpaQueryfier(getLoanIssueTransactionsSQL, JPAUtil.em()).with(LoanId)
                .queryfyNative(Transaction.class).getResultList();

    }

}
